<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>选择计划单明细</h1>
</section>
<section class="content">
    <input id="reportType" type="hidden" th:value="${sheet.reportType}">
    <input id="sheetId" type="hidden" th:value="${sheet.id}">
    <input id="sheetType" type="hidden" th:value="${sheet.sheetType}">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <!--<div class="box-header">
                    <div class="col-xs-12">
                        <div class="col-xs-offset-4 col-xs-4">
                            <h1 class="text-center" th:each="type : ${repTypes}" th:if="${type.value == sheet.reportType}" th:text="${type.name}"></h1>
                        </div>
                    </div>
                    <div class="col-xs-12" style="margin-top: 15px">
                        <div class="col-xs-2">
                            <h4>项目编号&emsp;[[${sheet.proCode}]]</h4>
                        </div>
                        <div class="col-xs-4">
                            <h4>项目名称&emsp;[[${sheet.proName}]]</h4>
                        </div>
                        <div class="col-xs-2">
                            <h4>项目数量&emsp;[[${sheet.proNum}]]</h4>
                        </div>
                        <div class="col-xs-2">
                            <h4>类型&emsp;[[${sheet.malType}]]</h4>
                        </div>
                        <div class="col-xs-2">
                            <h4>部分&emsp;[[${sheet.part}]]</h4>
                        </div>
                    </div>
                </div>-->
                <div class="box-body" ><!--style="padding-left: 45px;padding-right: 45px"-->
                    <div class="col-xs-12">
                        <div class="col-xs-12">
                            <div class="form-inline">
                                <a shiro:hasPermission="report:list:cha" href="javascript:void(0);"
                                   class="btn btn-success pull-right" style="margin-right: 10px"
                                   onclick="selected()">
                                    <span class="Bold">确定</span>
                                </a>
                            </div>
                            <table id="bootstrap-table"></table>

                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table, columns,
        sheetId = +$("#sheetId").val(),
        sheetType = +$("#sheetType").val(),
        reportType = +$("#reportType").val();

    /** 选择计划 */
    function selected() {
        let arr = js.table.selectColumns(table, "id");
        if (arr.length < 1) {
            js.modal.alert("请选择要变更的计划");
            return;
        }
        location.href = ctx + 'report/list/changePage?sheetId=' + sheetId + '&ids='+arr
    }

    /** 选择计划提报类型 */
    function handlerPage() {
        switch (reportType) {
            case 1:
                if (sheetType === 1) {
                    columns = [
                        {
                            checkbox: true,
                            formatter: function (value, row) {
                                if (row.alreadyChange === 1 || row.isReturn === 1) {
                                    return {disabled: true}
                                } else {
                                    return {disabled: false}
                                }
                            }
                        },
                        {title: "物料描述", field: 'malDesc'},
                        {title: "数量", field: 'num'},
                        {title: "单位", field: 'unit'},
                        {title: "型号/标准号", field: 'standard'},
                        {title: "品牌", field: 'brand'},
                        {title: "备注", field: 'remark'},
                        {
                            title: "附件", field: 'url',
                            formatter: function (value) {
                                if (value) {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                                return '';
                            }
                        }
                    ];
                } else {
                    columns = [
                        {
                            checkbox: true,
                            formatter: function (value, row) {
                                if (row.alreadyChange === 1) {
                                    return {disabled: true}
                                } else {
                                    return {disabled: false}
                                }
                            }
                        },
                        {title: "原物料描述", field: 'malDesc'},
                        {title: "原数量", field: 'num'},
                        {title: "原单位", field: 'unit'},
                        {title: "原型号/标准号", field: 'standard'},
                        {title: "原品牌", field: 'brand'},
                        {title: "原备注", field: 'remark'},
                        {title: "原附件", field: 'url',
                            formatter: function (value) {
                                if (value) {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                                return '';
                            }
                        },
                        {title: "新物料描述", field: 'afterMalDesc',
                            formatter: function (value, row) {
                                if (value === row.malDesc) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新数量", field: 'afterNum',
                            formatter: function (value, row) {
                                if (value === row.num) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新单位", field: 'afterUnit',
                            formatter: function (value, row) {
                                if (value === row.unit) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新型号/标准号", field: 'afterStandard',
                            formatter: function (value, row) {
                                if (value === row.standard) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新品牌", field: 'afterBrand',
                            formatter: function (value, row) {
                                if (value === row.brand) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新备注", field: 'afterRemark',
                            formatter: function (value, row) {
                                if (value === row.remark) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新附件", field: 'afterUrl',
                            formatter: function (value, row) {
                                if (value === row.url) {
                                    return '';
                                } else {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                            }
                        }
                    ];
                }
                break;
            case 2:
                if (sheetType === 1) {
                    columns = [
                        {checkbox: true,
                            formatter: function (value, row) {
                                if (row.alreadyChange === 1 || row.isReturn === 1) {
                                    return {disabled: true}
                                } else {
                                    return {disabled: false}
                                }
                            }
                        },
                        {title: "物料描述", field: 'malDesc'},
                        {title: "图号", field: 'diagram'},
                        {title: "数量", field: 'num'},
                        {title: "单位", field: 'unit'},
                        {title: "外协类型", field: 'assistType'},
                        {title: "备注", field: 'remark'},
                        {title: "附件", field: 'url',
                            formatter: function (value) {
                                if (value) {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                                return '';
                            }
                        }
                    ];
                } else {
                    columns = [
                        {
                            checkbox: true,
                            formatter: function (value, row) {
                                if (row.alreadyChange === 1) {
                                    return {disabled: true}
                                } else {
                                    return {disabled: false}
                                }
                            }
                        },
                        {title: "原物料描述", field: 'malDesc'},
                        {title: "原图号", field: 'diagram'},
                        {title: "原数量", field: 'num'},
                        {title: "原单位", field: 'unit'},
                        {title: "原外协类型", field: 'assistType'},
                        {title: "原备注", field: 'remark'},
                        {title: "原附件", field: 'url',
                            formatter: function (value) {
                                if (value) {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                                return '';
                            }
                        },
                        {title: "新物料描述", field: 'afterMalDesc',
                            formatter: function (value, row) {
                                if (value === row.malDesc) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新图号", field: 'afterDiagram',
                            formatter: function (value, row) {
                                if (value === row.diagram) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新数量", field: 'afterNum',
                            formatter: function (value, row) {
                                if (value === row.num) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新单位", field: 'afterUnit',
                            formatter: function (value, row) {
                                if (value === row.unit) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新外协类型", field: 'afterAssistType',
                            formatter: function (value, row) {
                                if (value === row.assistType) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新备注", field: 'afterRemark',
                            formatter: function (value, row) {
                                if (value === row.remark) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新附件", field: 'afterUrl',
                            formatter: function (value, row) {
                                if (value === row.url) {
                                    return '';
                                } else {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                            }
                        }
                    ];
                }

                break;
            case 3:
                if (sheetType === 1) {
                    columns = [
                        {checkbox: true,
                            formatter: function (value, row) {
                                if (row.alreadyChange === 1 || row.isReturn === 1) {
                                    return {disabled: true}
                                } else {
                                    return {disabled: false}
                                }
                            }
                        },
                        {title: "物料描述", field: 'malDesc'},
                        {title: "数量", field: 'num'},
                        {title: "单位", field: 'unit'},
                        {title: "型号/标准号", field: 'standard'},
                        {title: "材质", field: 'quality'},
                        {title: "使用库存", field: 'useStore',
                            formatter: function (value) {
                                if (value === 1) {
                                    return '<span class="badge label-success">是</span>';
                                } else if (value === 2) {
                                    return '<span class="badge label-inverse">否</span>';
                                }
                            }
                        },
                        {title: "备注", field: 'remark'},
                        {title: "附件", field: 'url',
                            formatter: function (value) {
                                if (value) {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                                return '';
                            }
                        }
                    ];
                } else {
                    columns = [
                        {
                            checkbox: true,
                            formatter: function (value, row) {
                                if (row.alreadyChange === 1) {
                                    return {disabled: true}
                                } else {
                                    return {disabled: false}
                                }
                            }
                        },
                        {title: "原物料描述", field: 'malDesc'},
                        {title: "原数量", field: 'num'},
                        {title: "原单位", field: 'unit'},
                        {title: "原型号/标准号", field: 'standard'},
                        {title: "原材质", field: 'quality'},
                        {title: "原使用库存", field: 'useStore',
                            formatter: function (value) {
                                if (value === 1) {
                                    return '<span class="badge label-success">是</span>';
                                } else if (value === 2) {
                                    return '<span class="badge label-inverse">否</span>';
                                }
                            }
                        },
                        {title: "原备注", field: 'remark'},
                        {title: "原附件", field: 'url',
                            formatter: function (value) {
                                if (value) {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                                return '';
                            }
                        },
                        {title: "新物料描述", field: 'afterMalDesc',
                            formatter: function (value, row) {
                                if (value === row.malDesc) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新数量", field: 'afterNum',
                            formatter: function (value, row) {
                                if (value === row.num) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新单位", field: 'afterUnit',
                            formatter: function (value, row) {
                                if (value === row.unit) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新型号/标准号", field: 'afterStandard',
                            formatter: function (value, row) {
                                if (value === row.standard) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新材质", field: 'afterQuality',
                            formatter: function (value, row) {
                                if (value === row.quality) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新使用库存", field: 'afterUseStore',
                            formatter: function (value, row) {
                                if (value === row.useStore) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新备注", field: 'afterRemark',
                            formatter: function (value, row) {
                                if (value === row.remark) {
                                    return '';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新附件", field: 'afterUrl',
                            formatter: function (value, row) {
                                if (value === row.url) {
                                    return '';
                                } else {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                            }
                        }
                    ];
                }
                break;
        }
    }

    $(function () {

        handlerPage();

        /** 加载列表 */
        table = js.table.init({
            url: sheetType === 1 ? ctx + "report/list/planList/" + sheetId : ctx + "report/list/changeList/" + sheetId,
            showExport: false,
            rowStyle: function (row, index) {
                if (row.isReturn === 1) {
                    return {
                        css: {color: 'red'}
                    };
                } else {
                    return {}
                }
            },
            columns: columns
        });

    });
</script>
</body>
</html>
